package com.qiantu.phone.ui.shotview;

import android.content.Context;

import com.qiantu.phone.R;
import com.qiantu.phone.widget.SwitchDeviceView;

import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER;
import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER_OFF;
import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER_ON;

/**
 * @ClassName DeviceLightView
 * @Description TODO
 * @Author ShiJunqiang
 * @Date 2021/12/8 23:05
 * @Version 1.0
 */
public class DeviceLightShutView extends BaseDeviceActView {
    private SwitchDeviceView switchView;
    public DeviceLightShutView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.light_device_ly;
    }

    @Override
    public void initView() {
        switchView = (SwitchDeviceView) findViewById(R.id.switch_view);
        switchView.setOnClickListener(new SwitchDeviceView.OnClickListener() {
            @Override
            public void onClick() {
                switchView.setState(!switchView.isOpen());
                addAct(POWER, switchView.isOpen()? POWER_ON : POWER_OFF);
            }
        });
    }

    @Override
    public void updateView() {
        //默认空的话，添加默认动作开
        if(mDeviceActMap.size() == 0){
            addAct(POWER, POWER_ON);
        }
        //根据已保存动作指令集合更新UI
        switchView.setState(POWER_ON.equals(getState(POWER, "0")));
    }
}
